package DEEPERsource.DEEPERsource.source.controllers;

import java.io.FileWriter;
import java.io.IOException;

import parser.Parser;
import parser.StanfordParser;
import preprocessing.SimplePreprocessor;
import corpus.CorpusPrinter;
import corpus.Text;
import corpus.ppi.CorpusFactory;

public class CorpusParser {
	/**
	 * 
	 * @param params
	 * Format:
	 * 	-xml xml_file_location
	 *  -serialized serialized_dir_location - optional arg
	 *  -output output_file
	 */
	public void run(String...params){
		String sourceXML = "", serialDir = "", out = "";
		for(int i = 0; i< params.length; i++){
			if(params[i].equals("-xml")){
				sourceXML = params[++i];
			}
			if(params[i].equals("-serialized")){
				serialDir = params[++i];
			}
			if(params[i].equals("-output")){
				out = params[++i];
			}
		}
		CorpusFactory cFactory = new CorpusFactory();
		Text corpus = cFactory.getCorpusFromPPIXML(sourceXML, new SimplePreprocessor());
		if(!serialDir.equals("")){
			corpus.parse(null,"serialized",serialDir);
		}else{
			Parser stanfordParser = new StanfordParser();
			stanfordParser.init("-maxLength","70","-dependencyType","typedDependenciesCCprocessed");
			corpus.parse(stanfordParser);
		}		
		/*CorpusPrinter printer = new CorpusPrinter();
		String txt = printer.printInARFF(corpus);
		FileWriter writer = null;
		try {
			writer = new FileWriter(out);
			writer.write(txt);
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (writer != null) {
				try {
					writer.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}*/
	}
}
